<?php

	//error_reporting(E_ERROR | E_WARNING | E_PARSE ); // Desactivar toda notificaci?n de error
	error_reporting(-1 ); // Desactivar toda notificaci?n de error

	//-------------------------------------------------------------------------------------Acceso a la BD
	if (preg_match('/xampp/', $_SERVER['DOCUMENT_ROOT'])) {
		//-------------------------------------------------------------------------------------Configuracion Local
		define('HOST'		, 'http://www.lionel.x');
		define('INST_DIR'	, '/aloja02');
		$server 	= 'localhost';
		$user 		= 'nando';
		$password 	= '62636';
		$database 	= 'aloja';
		$driver		= 'mysqli';
	//	error_reporting(E_ALL); // Notificar todos los errores de PHP (ver el registro de cambios)
	} else {
		define('HOST'		, 'http://www.rosarioalojamientos.com');
		define('INST_DIR'	, '');
		$server 	= 'localhost';
		$user 		= 'rosaloja_nando';
		$password 	= 'Dolci62636';
		$database 	= 'rosaloja_alojamientos';
		$driver		= 'mysqli';

	}

	// ------------------------------------------------------------------ Rutas
	define('RUTA'	, HOST.INST_DIR);

	if (substr ($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
		$root = substr($_SERVER['DOCUMENT_ROOT'],0,(strlen($_SERVER['DOCUMENT_ROOT'])-1));
	} else { $root = $_SERVER['DOCUMENT_ROOT']; }

	define('ROOT',		$root.INST_DIR			    );
	define('URL', 		HOST.INST_DIR               );
	define('IMG', 		HOST.INST_DIR.'/img/'       );
	define('VER_FOTOS',	URL."/archivos/images/alojamientos" );

	//--------------------------------------------------------------------Conexion BD
	if ( !isset($mipath) ) { $mipath=''; }
	include(ROOT.'/adodb/adodb-time.inc.php');
	include(ROOT.'/adodb/adodb.inc.php');
	$ADODB_CACHE_DIR = '/temp'; 
	$db = ADONewConnection($driver); 
	$db->PConnect('localhost',$user,$password,$database);
	$db->SetFetchMode(ADODB_FETCH_ASSOC);
	$db->debug = false;
	$db->cacheSecs = 3600;


	include_once(ROOT.'/inc/inc_localidades.php');


	//-------------------------------------------------------------------------------------	
	//                                                                            Funciones
	//-------------------------------------------------------------------------------------
	function array_to_json( $array ){

	    if( !is_array( $array ) ){
	        return false;
	    }

	    $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
	    if( $associative ){

	        $construct = array();
	        foreach( $array as $key => $value ){

	            // We first copy each key/value pair into a staging array,
	            // formatting each key and value properly as we go.

	            // Format the key:
	            if( is_numeric($key) ){
	                $key = "key_$key";
	            }
	            $key = "\"".addslashes($key)."\"";

	            // Format the value:
	            if( is_array( $value )){
	                $value = array_to_json( $value );
	            } else if( !is_numeric( $value ) || is_string( $value ) ){
	                $value = "\"".addslashes($value)."\"";
	            }

	            // Add to staging array:
	            $construct[] = "$key: $value";
	        }

	        // Then we collapse the staging array into the JSON form:
	        $result = "{ " . implode( ", ", $construct ) . " }";

	    } else { // If the array is a vector (not associative):

	        $construct = array();
	        foreach( $array as $value ){

	            // Format the value:
	            if( is_array( $value )){
	                $value = array_to_json( $value );
	            } else if( !is_numeric( $value ) || is_string( $value ) ){
	                $value = "'".addslashes($value)."'";
	            }

	            // Add to staging array:
	            $construct[] = $value;
	        }

	        // Then we collapse the staging array into the JSON form:
	        $result = "[ " . implode( ", ", $construct ) . " ]";
	    }

	    return $result;
	}

	//---------------------------------------------------------------------
	//                                                     Print_r elegante
	//---------------------------------------------------------------------
	function pr($array,$die=null) {
		echo '<div style="width:100%;text-align:left; align:left;text-shadow:none;"><pre>';print_r($array); echo "</pre></div>";
		if (isset($die) AND $die==1) {die();}
	}

	//---------------------------------------------------------------------
	//                                                          Request_var
	//---------------------------------------------------------------------
	function request($variable='xvar', $default='', $formato='trim', $limite=5){
		
		if ( isset($_POST[$variable]) and !empty($_POST[$variable]) ) {
			$valor = $_POST[$variable];

		} elseif ( isset($_GET[$variable]) ) {
			$valor = $_GET[$variable];
		} else {
			$valor = $default;
		}

		switch ($formato){
			case 'html':
				$valor = trim(htmlspecialchars($valor,ENT_QUOTES,'UTF-8')); 
				break;
			case 'ltrim':
				$valor = trim(strtolower($valor));		
				break;
			case 'trim':
				$valor = trim($valor);		
				break;
			case 'int':
				$valor = intval(($valor));		
				break;
				
		}

		if( $limite>0 ) { $valor = substr($valor,0,$limite); }
		
		return $valor;
	}



?>